<template>
  <view>
    <swiper class="swiper" :indicator-dots="true" :circular="true" :autoplay="true" :interval="3000" :duration="1000">
      <swiper-item v-for="(swiper,i) in swiperList" :key="i">
        <navigator class="swiper-item" :url="`/subpkg_goods/goods_detail/goods_detail?goods_id=${swiper.goods_id}`">
          <image :src="swiper.image_src"></image>
        </navigator>
      </swiper-item>
    </swiper>
  </view>
</template>

<script>
  export default {
    name:'home-swiper',
    data() {
      return {
        swiperList: []
      };
    },
    methods: {
      async initSwiper() {
        await uni.$http.get('/api/public/v1/home/swiperdata').then(res => {
          if (res.data.meta.status !== 200) {
            return uni.$showMsg()
          }
          // 3.3 请求成功，为 data 中的数据赋值
          this.swiperList = res.data.message
        })
      }
    },
    created() {
      // 初始化轮播图
      this.initSwiper()
    }
  }
</script>

<style lang="scss" scoped>

.swiper {
  height: 330rpx;
  .swiper-item,image {
    width: 100%;
    height: 100%;
  }
}


</style>
